package interfaz_usuario;

import java.awt.BorderLayout;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class HeadMenuPanel extends JPanel{
	
	private JMenuBar barMenuFile;
	private JMenu menuFile;
	private JMenuItem itemNew;
	private JMenuItem itemSave;
	private JMenuItem itemLoad;
	
	
	private JMenuBar barMenuView;
	private JMenu menuView;
	private JMenuItem itemBigBox;
	
	private BtnNewClicked buttonNew;
	
	public HeadMenuPanel (){
		setVisible(true);
		//initialize menu Archivo
		barMenuFile= new JMenuBar();
		menuFile = new JMenu("Archivo");
		itemNew = new JMenuItem("Nuevo");
		itemSave = new JMenuItem("Guardar");
		itemLoad = new JMenuItem("Cargar");
		
		//initialize menu Ver
		barMenuView = new JMenuBar();
		menuView= new JMenu("Ver");
		itemBigBox= new JMenuItem("Crear Cuadrados");
		
		//composing menu Archivo
		menuFile.add(itemNew);
		menuFile.add(itemSave);
		menuFile.add(itemLoad);
		barMenuFile.add(menuFile);
		
		//composing menu ver
		menuView.add(itemBigBox);
		barMenuView.add(menuView);
		
		
		//composing all
		add(barMenuFile);
		add(barMenuView);
		setAlignmentX(0);
		setAlignmentY(0);
		
		buttonNew = new BtnNewClicked();
		
		
		//Actions when a button is clicked
		itemNew.addActionListener(buttonNew);
		
			
	}

	public JMenuItem getItemBigBox() {
		return itemBigBox;
	}

	public void setItemBigBox(JMenuItem itemBigBox) {
		this.itemBigBox = itemBigBox;
	}

	public BtnNewClicked getButtonNew() {
		return buttonNew;
	}

	public void setButtonNew(BtnNewClicked buttonNew) {
		this.buttonNew = buttonNew;
	}

	public JMenuItem getItemNew() {
		return itemNew;
	}

	public void setItemNew(JMenuItem itemNew) {
		this.itemNew = itemNew;
	}

	public JMenuItem getItemSave() {
		return itemSave;
	}

	public void setItemSave(JMenuItem itemSave) {
		this.itemSave = itemSave;
	}

	public JMenuItem getItemLoad() {
		return itemLoad;
	}

	public void setItemLoad(JMenuItem itemLoad) {
		this.itemLoad = itemLoad;
	}


	public class BtnNewClicked implements ActionListener{
		int width;
		int height;
		JButton okButton;
		JTextField textWidth;
		JTextField textHeight;
		JDialog window;
		
		public BtnNewClicked(){
			width=0;
			height=0;
			textHeight = new JTextField();
			textWidth = new JTextField();
			okButton= new JButton("OK");
			//okBoton.addActionListener(new BotonOkClicked());
		}
		
		
		@Override
		public void actionPerformed(ActionEvent e) {
			System.out.println("Me clickearon NUEVO");
			//setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
			//setPreferredSize(new Dimension(40,50));
			window = new JDialog();
			window.setVisible(true);
			window.setLocation(200, 200);
			window.setSize(200, 200);
			window.setLayout(new BorderLayout());
			
			textWidth.setPreferredSize(new Dimension(50,20));
			textHeight.setPreferredSize(new Dimension(50,20));
			JPanel p = new JPanel();
			p.setLayout(new FlowLayout());
			p.add(new Label("Ancho: "));
			p.add(textWidth);
			p.add(new Label("Alto: "));
			p.add(textHeight);
			
			window.add(p,BorderLayout.NORTH);
			window.add(okButton,BorderLayout.CENTER);
			
			
			window.pack();
					
			
		}


		public JButton getOkButton() {
			return okButton;
		}


		public void setOkButton(JButton okButton) {
			this.okButton = okButton;
		}


		public JTextField getTextWidth() {
			return textWidth;
		}


		public void setTextWidth(JTextField textWidth) {
			this.textWidth = textWidth;
		}


		public JTextField getTextHeight() {
			return textHeight;
		}


		public void setTextHeight(JTextField textHeight) {
			this.textHeight = textHeight;
		}


		public void setVisible(boolean v){
			window.setVisible(v);
		}
		
	}
}
